package com.zy.edu.controller;


import com.zy.edu.bean.Course;
import com.zy.edu.bean.CourseType;
import com.zy.edu.bean.InputParam;
import com.zy.edu.bean.Jurisdiction;
import com.zy.edu.service.CourseService;
import com.zy.edu.service.CourseService;
import com.zy.edu.service.CourseTypeService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HuangHaiShui
 * @since 2021-07-17
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Resource
    CourseService courseService;

    @Resource
    CourseTypeService courseTypeService;

    /**
     * @Author: HuangHaiShui
     * @Description: 数据的新增与修改
     * @Date: 9:17 2021/7/14
     * @param course:
     * @return: Map
     **/
    @RequestMapping("/edit")
    public Map edit(@Valid Course course, InputParam inputParam){
        return courseService.saveOrUpdate(course,inputParam);
    }
    @RequestMapping("/list")
    public Map list( Course course, InputParam inputParam){

        return courseService.list(course, inputParam);
    }


    /**
     * @Author: HuangHaiShui
     * @Description: 删除数据
     * @Date: 9:18 2021/7/14
     * @param course:  传入id 字段
     * @return: Map
     **/
    @RequestMapping("/dele")
    public Map dele( Course course){
        return courseService.dele(course);
    }

    //获取课程以及下属所有课时
    @RequestMapping("/getById")
    public Map getById(Course course, InputParam inputParam){

        return courseService.getById(course, inputParam);
    }

//    //根据学生的id以及课程id，获取这个学生的所有课时数据
//    @RequestMapping("/getByStuId")
//    public Map findAllByStuId(InputParam inputParam){
//
//        return courseService.findAllByStuId(inputParam);
//    }
//    //根据班级的id以及课程id，获取这个班级的所有课时数据
//    @RequestMapping("/getByCourseAndClsId")
//    public Map findAllByClsId(InputParam inputParam){
//
//        return courseService.findAllByClsId(inputParam);
//    }

    //根据班级的id以及课程id，获取这个班级的所有课时数据
    //根据学生的id以及课程id，获取这个学生的所有课时数据
    @RequestMapping("/getAllAndRecord")
    public Map getAllAndRecord(InputParam inputParam){

        return courseService.getAllAndRecord(inputParam);
    }

    //课程封面的上传
    @RequestMapping("photo")
    public Map photo(MultipartFile file, @Valid InputParam inputParam  ) throws IOException {

        return courseService.photo(file,inputParam);
    }

    ////-------------课程类型--------------

    @RequestMapping("/type/edit")
    public Map edit(@Valid CourseType courseType, InputParam inputParam){
        return courseTypeService.saveOrUpdate(courseType,inputParam);
    }
    @RequestMapping("/type/dele")
    public Map dele( CourseType courseType){
        return courseTypeService.dele(courseType);
    }

    @RequestMapping("/type/list")
    public Map list( CourseType courseType, InputParam inputParam){

        return courseTypeService.list(courseType, inputParam);
    }

}

